package com.zhilifang.modules.zlf.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhilifang.modules.zlf.entity.ImgTitleAlt;
import com.zhilifang.modules.zlf.service.impl.ImgTitleAltServiceImpl;
import com.zhilifang.modules.zlf.utils.Pager;
import com.zhilifang.modules.zlf.utils.QueryString;
import com.zhilifang.modules.zlf.utils.Result;

/**
 * Controller 后台>>标签管理Controller
 */
@Controller
@RequestMapping("/imgTitleAltController")
public class ImgTitleAltController {

	@Autowired
	private ImgTitleAltServiceImpl imgTitleAltServiceImpl  ;
	
	
	
	
	/**
	 * 根据表名查询图片信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/selectTableNameImg", method = RequestMethod.POST)
	@ResponseBody
	public Pager<ImgTitleAlt> selectTableNameImg(String tableName,QueryString queryString){
		Pager<ImgTitleAlt> pager = new Pager<ImgTitleAlt>();
		ImgTitleAlt read = new ImgTitleAlt();
		if(!"".equals(queryString.getReady01())&&queryString.getReady01()!=null){
			read.setTitle("%"+queryString.getReady01()+"%");			//标题
		}
		if(!"".equals(queryString.getReady02())&&queryString.getReady02()!=null){
			read.setAlt("%"+queryString.getReady02()+"%");		//标签
		}
		String[] idArray = null;
		List<ImgTitleAlt> list = imgTitleAltServiceImpl.selectTableNameImg(tableName, read.getTitle(),read.getAlt(),idArray);
		if (list != null&&!list.isEmpty()) {
			pager=new Pager<ImgTitleAlt>(queryString.getCurrentPage(),queryString.getPageSize(), list);
		}
		return pager;
	}
	
	
	/**
	 * 详情
	 * 
	 * @return
	 */
	@RequestMapping(value = "/selectTableNameById", method = RequestMethod.POST)
	@ResponseBody
	public ImgTitleAlt selectTableNameById(String tableName,ImgTitleAlt read){
		return imgTitleAltServiceImpl.selectTableNameById(tableName, read.getId());
	}
	
	
	/**
	 * 修改
	 * 
	 * @return
	 */
	@RequestMapping(value = "/updateImgTitleAlt", method = RequestMethod.POST)
	@ResponseBody
	public Result updateImgTitleAlt(String tableName,ImgTitleAlt read){
		Result result = new Result();
		imgTitleAltServiceImpl.updateImgTitleAlt(tableName, read.getTitle(), read.getAlt(), read.getId());
		result.setState("200");
		result.setMessage("修改成功。");
		return result;
	}

	
}
